package main;

import java.util.ArrayList;

public class Army {
	
	public Game game;
	public ArrayList<Unit> units;
	public ArrayList<Unit> removedUnits = new ArrayList<Unit>();
	public int origSize = 0;
	
	public Army(Game g) {
		this.game = g;
		this.units = new ArrayList<Unit>();
	}
	
	public Army(ArrayList<Unit> units, Game g) {
		this.game = g;
		this.units = units;
		this.origSize = units.size();
		for(Unit u : this.units) {
			u.game = this.game;
			u.army = this;
		}
	}
	
	public void addUnit(Unit u) {
		this.units.add(u);
		this.origSize += 1;
		u.game = this.game;
		u.army = this;
	}
	
	public void removeUnit(Unit u) {
		this.units.remove(u);
		if (!this.removedUnits.contains(u))
			this.removedUnits.add(u);
	}
	
	public void removeUnit(int id) {
		Unit a = null;
		for (Unit u : units) {
			if (u.id == id) {
				a = u;
				break;
			}
		}
		if (a != null)
			this.units.remove(a);
			this.removedUnits.add(a);
	}
	
	public void addToGame(Game g) {
		this.game = g;
		for(Unit u : this.units){
			u.game = g;
		}
	}
}